package com.zee.activity.ui

import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity

import com.zee.activity.R
import com.zee.listener.OnActivityResultListener
import com.zee.log.ZLog
import com.zee.route.ZRouter
import kotlinx.android.synthetic.main.activity_callback_a.*
import java.lang.StringBuilder

class CallbackActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_callback_a)

        id_click_callback_a_view.setOnClickListener {
            ZRouter.getInstance().startActivity(Test2CallbackActivity::class.java).requestCodeCallBack(object : OnActivityResultListener {
                override fun onActivityResult(data: Intent) {
                    val result = StringBuilder(data.getStringExtra("result"))
                    id_click_callback_a_view.text = result.append("    Fragment").toString();
                }
            }).letsGo()
        }
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (resultCode == 10) {
            ZLog.i("进入onActivityResult()")
            val result = StringBuilder(data!!.getStringExtra("result"))
            id_click_callback_a_view.text = result.append("    Activity").toString();
        }
    }
}
